

#ifndef MY_GERRORMSG
#define MY_GERRORMSG

void gErrorMsgW(DWORD dwError, PWSTR first, ...) {

	PWSTR lpMsgBuf;
	FormatMessageW( 
	    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
	    FORMAT_MESSAGE_FROM_SYSTEM | 
	    FORMAT_MESSAGE_IGNORE_INSERTS,
	    NULL,
	    dwError,
	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
	    (PWSTR) &lpMsgBuf,
	    0,
	    NULL 
	);

	wstring buf = lpMsgBuf;
	// Free the buffer.
	LocalFree( lpMsgBuf );

	// Process any inserts in lpMsgBuf.
	PWSTR* p = &first;
	while(*p != NULL) {
	        buf = buf + L"\r\n" + (*p);
		p++;
	}

	// Display the string.
	MessageBoxW( GetDesktopWindow(), buf.c_str(), L"Error", MB_OK | MB_ICONERROR );


}

void gErrorMsgA(DWORD dwError, LPCTSTR title) {

	char* lpMsgBuf;
	FormatMessageA( 
	    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
	    FORMAT_MESSAGE_FROM_SYSTEM | 
	    FORMAT_MESSAGE_IGNORE_INSERTS,
	    NULL,
	    dwError,
	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
	    (char*)&lpMsgBuf,
	    0,
	    NULL 
	);

	// Display the string.
	MessageBoxA( GetDesktopWindow(), lpMsgBuf, title, MB_OK | MB_ICONERROR );

	// Free the buffer.
	LocalFree( lpMsgBuf );

}


#endif
